package com.xieyingwangluo.yxpart.utils;


import com.xieyingwangluo.yxpart.entity.PartModel;
import jxl.Sheet;
import jxl.Workbook;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class ExcelUtil {
    public static List<PartModel> read(File file){
        List<PartModel> list = new ArrayList<PartModel>();
        try {
            Workbook workbook = Workbook.getWorkbook(file);
            Sheet sheet = workbook.getSheet(0);
            for(int i = 1;i < sheet.getRows();i++) {
                PartModel partModel = new PartModel();
                partModel.setName(sheet.getCell(1,i).getContents());
                partModel.setSalary(Integer.parseInt(sheet.getCell(2,i).getContents()));
                partModel.setType(Integer.parseInt(sheet.getCell(3,i).getContents()));
                partModel.setUnit(Integer.parseInt(sheet.getCell(4,i).getContents()));
                partModel.setLabour(Integer.parseInt(sheet.getCell(5,i).getContents()));
                partModel.setSetcycle(Integer.parseInt(sheet.getCell(7,i).getContents()));
                partModel.setHirnumb(Integer.parseInt(sheet.getCell(8,i).getContents()));
                partModel.setSex(Integer.parseInt(sheet.getCell(9,i).getContents()));
                partModel.setContent(sheet.getCell(10,i).getContents());
                /*partModel.setStart_time(DateUtil.StD(sheet.getCell(10,i).getContents(),"yyyy/MM/dd HH:mm:ss"));
                partModel.setEnd_time(DateUtil.StD(sheet.getCell(11,i).getContents(),"yyyy/MM/dd HH:mm:ss"));*/
                partModel.setJob_address(sheet.getCell(13,i).getContents());
                partModel.setState(Integer.parseInt(sheet.getCell(14,i).getContents()));
                partModel.setMerchant_id(sheet.getCell(15,i).getContents());
                list.add(partModel);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
